//
//  appConfig.swift
//  worldexchange
//
//  Created by xionghao on 2019/1/9.
//  Copyright © 2019 xionghao. All rights reserved.
//

import Foundation
import Moya
import MJRefresh

var HOST_URL = "http://www.worldchange3.com"
var IMAGE_HOST = "http://www.worldchange3.com/"

let changeCurrencyNoticeName = "changeCurrencyNotice"

let changeShopNoticeName = "changeShopNoticeName"

let appMoneyLoadEndNoticeName = "appMoneyLoadEndNoticeName"

let LanguageChangeNotice = "LanguageChangeNotice"

var defaultCurrency:String {
    get {
        let defaultCurrency = UserDefaults.standard.string(forKey: "defaultCurrency") ?? "THB"
        return "THB"
    }
    set(value){
        UserDefaults.standard.set(value, forKey: "defaultCurrency")
    }
}


var provider = MoyaProvider<WE>()
var appRateItems:[RateItem] = []
var appMoneyItems:[MoneyItem] = []
var appShopItems:[ShopItem] = []
var aboutItem:ArticleItem = ArticleItem()
var processItem:ArticleItem = ArticleItem()
var currentShop:ShopItem? {
    get {
        let currentShopString = UserDefaults.standard.string(forKey: "currentShop") ?? ""
        if currentShopString == "" {
            return nil
        }else {
            return ShopItem.deserialize(from: currentShopString)!
        }
    }
    set(value) {
        if value != nil {
            UserDefaults.standard.set(value!.toJSONString(), forKey: "currentShop")
        }else {
             UserDefaults.standard.set("", forKey: "currentShop")
        }
       
    }
}

var lastUpdateTime:String = ""
var isLogin:Bool  {
    get {
        let Login = UserDefaults.standard.bool(forKey: "isLogin")
        return Login
    }
    set(value) {
        UserDefaults.standard.set(value, forKey: "isLogin")
    }
}
var userData:UserDataItem? {
    get {
        let string = UserDefaults.standard.string(forKey: "userData") ?? ""
        let item = UserDataItem.deserialize(from: string)
        return item
    }
    set(value) {
        if value == nil {
            UserDefaults.standard.removeObject(forKey: "userData")
        }else {
            UserDefaults.standard.set(value!.toJSONString(), forKey: "userData")
        }
      
    }
}

var appEmail:String  {
    get {
        let email = UserDefaults.standard.string(forKey: "email") ?? "worldchange3@hotmail.com"
        return email
    }
    set(value) {
        UserDefaults.standard.set(value, forKey: "email")
    }
}

var appThirdUser:String  {
    get {
        let email = UserDefaults.standard.string(forKey: "thirdUser") ?? "worldchange3"
        return email
    }
    set(value) {
        UserDefaults.standard.set(value, forKey: "thirdUser")
    }
}


